import request from '@/axios/request'

const api_name = '/knowledge'

export default {
  /**
   * 添加知识点
   * @param {Object} knowledge - 知识点信息
   * @param {string} knowledge.title - 标题
   * @param {string} knowledge.description - 描述
   * @param {number} knowledge.courseId - 课程ID
   * @param {string} knowledge.mainModule - 主模块
   * @param {string} knowledge.subModule - 子模块
   * @param {number} knowledge.difficultyId - 难度ID
   */
  addKnowledge(knowledge) {
    return request({
      url: `${api_name}`,
      method: 'post',
      data: knowledge
    })
  },

  /**
   * 分页查询知识点
   * @param {Object} params - 查询参数
   * @param {number} params.courseId - 课程ID
   * @param {number} params.page - 页码
   * @param {number} params.pageSize - 每页数量
   */
  getKnowledgeList(params) {
    return request({
      url: `${api_name}/page`,
      method: 'post',
      data: params,
      headers: {
        'Content-Type': 'application/json'
      }
    })
  },

  /**
   * 更新知识点
   * @param {Object} knowledge - 知识点更新信息
   * @param {number} knowledge.id - 知识点ID
   * @param {string} knowledge.title - 标题
   * @param {string} knowledge.description - 描述
   * @param {number} knowledge.difficultyId - 难度ID
   */
  updateKnowledge(knowledge) {
    return request({
      url: `${api_name}`,
      method: 'put',
      data: knowledge
    })
  },

  /**
   * 删除知识点
   * @param {number} knowledgeId - 知识点ID
   */
  deleteKnowledge(knowledgeId) {
    return request({
      url: `${api_name}/${knowledgeId}`,
      method: 'delete'
    })
  },

  /**
   * 导出知识点模板
   */
  exportTemplate() {
    return request({
      url: `${api_name}/export/template`,
      method: 'get',
      responseType: 'blob'
    })
  },

  /**
   * 导入知识点
   * @param {FormData} formData - 包含文件和courseId的表单数据
   */
  importKnowledge(formData) {
    return request({
      url: `${api_name}/import`,
      method: 'post',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      data: formData
    })
  },

  /**
   * 导出知识点Excel
   * @param {number} courseId - 课程ID
   */
  exportKnowledge(courseId) {
    return request({
      url: `${api_name}/export`,
      method: 'get',
      params: { courseId },
      responseType: 'blob'
    })
  }
}